package jzOffer;

public class Num18 {
    public ListNode deleteNode(ListNode head, int val) {
        if(head==null) return null;
        if(head.val==val) return head.next;
        ListNode dummyHead=new ListNode(-1);
        ListNode prev=head,cur=head.next;
        while(cur!=null && cur.val!=val){
            prev=cur;
            cur=cur.next;
        }
        if(cur!=null) prev.next=cur.next;
        return head;
    }
}
